I used the most direct method I could think of to put together the output string: compare every input atom (apart from the first) with the atom before it, then either increase the value of the current metal counter on the output if there is a match, or attach a lead-metal pair to the end of the output if there is no match.

I couldn't think of a way to do this comparison directly using the input atoms, since the rules state that only one copy of the input can be pulled for every output.
Instead, the machine first converts the value of the current input atom into a stick of quicksilvers, creates a copy if necessary, and then passes on the stick to be compared with the stick for the previous atom. The sticks are then converted back into metals and then placed on a purifier to check for a match. If there is a match, there will be an atom on the purifier output, and the presence or absence of this atom is used to implement the correct conditionals for the output string.

To check for matching golds, before converting the quicksilver sticks back into metals, the machine first checks whether there is a quicksilver in the 5th position for each of the incoming sticks, and conditionally passes a lead atom onto the purifier for each gold detected.

Very interesting puzzle, and most likely the math and computer gurus in the community have come up with more esoteric algorithms, which I look forward to seeing on stream.